package org.actions.event;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;   
import java.util.Map;
import java.sql.Timestamp;
import org.data.Event;
import org.util.EventDAO;
import org.util.DateUtil;

/**
 *
 * New simple event creation.
 * FROM: add_event.jsp
 * TO: event.jsp
 *
 * @author George.Mavchun
 */
public class CreateEventAction extends ActionSupport {
    private String name;
    private String place;
    private Timestamp timestamp;
    private Integer eventId;

    private String tempDateString;

    @Override
    public String execute() {   
        Map session = ActionContext.getContext().getSession();
        Integer user_id = (Integer)session.get("id");
        Event bean = new Event(null, user_id, name, place, timestamp);
        if (bean != null) {  
            eventId = EventDAO.addEvent(bean);
        }
        return SUCCESS;      
    }   
    
    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getEventId() {
        return eventId.toString();
    }
    
    public String getDateTimeString() {
        return DateUtil.format(timestamp.getTime(), DateUtil.DATE_AND_TIME_DISPLAY_FORMAT);
    }
    
    public void setDateString(String dateString) {
        tempDateString = dateString;
        int idx = tempDateString.indexOf("T");
        tempDateString = tempDateString.substring(0, idx);
    }
    
    public void setTimeString(String timeString) {
        int idx = timeString.indexOf("T");
        timeString = timeString.substring(idx, timeString.length());
        timestamp = new Timestamp(DateUtil.parseRFC(tempDateString  + timeString));
    }

    public String getPlace(){
        return place;
    }

    public void setPlace(String place){
        this.place = place;
    }
}
